using System;
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;

[Serializable]
public class ShakeEffectComponent : TakeDamageEffectBaseComponent
{
    public List<Transform> ShakeGameObjects = new List<Transform>();

    // public List<Sequence> Sequences = new List<Sequence>();

    public Vector3 ShakeRotation = new Vector3(0, 0, 15f);

    public override void OnAwake()
    {
        base.OnAwake();
        // for (int i = 0;i<ShakeGameObjects.Count;i++) {
        //     Sequences.Add(DOTween.Sequence());
        // }

        
    }
    public override void TakeDamageEffectPlay(GameObject AttackObject)
    {
        base.TakeDamageEffectPlay(AttackObject);
        // Debug.LogError("111111111111111111");

        for (int i = 0; i < ShakeGameObjects.Count; i++)
        {
            int temp = i;
            if (!ShakeGameObjects[temp].gameObject.activeSelf)
            {
                continue;
            }
            ShakeGameObjects[i].transform.DOKill();
            ShakeGameObjects[i].localEulerAngles = Vector3.zero;

            // // 添加一个快速的左右晃动
            // sequence.Append(ShakeGameObjects[i].DORotate(ShakeRotation, 0.05f, RotateMode.LocalAxisAdd).SetEase(Ease.OutQuad))
            //             .Append(ShakeGameObjects[i].DORotate(-ShakeRotation, 0.05f, RotateMode.LocalAxisAdd).SetEase(Ease.InOutQuad))
            //             .Append(ShakeGameObjects[i].DORotate(Vector3.zero, 0.05f, RotateMode.LocalAxisAdd).SetEase(Ease.InQuad));
            ShakeGameObjects[temp].DOLocalRotate(ShakeRotation, 0.05f).SetEase(Ease.OutQuad).OnComplete(() =>
            {
                ShakeGameObjects[temp].DOLocalRotate(-ShakeRotation, 0.05f).SetEase(Ease.InOutQuad).OnComplete(() =>
                {
                    ShakeGameObjects[temp].DOLocalRotate(Vector3.zero, 0.05f).SetEase(Ease.InQuad).OnComplete(() =>
                    {
                    });
                });
            });

        }
    }
}
